<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
  <link rel="stylesheet" href="style/css/bootstrap.min.css">
  <link rel="stylesheet" href="style/css/common.css">
  <style>
    .tips{padding: 0 10px;}
    .tips a{margin-left: 4px; color: red;}
    .tab-index-main>div{border-radius: 4px; background: #f5f5f5; border: 1px solid #d0d0d0; padding: 10px;}
  </style>
</head>
<body>
  <div class="container">
    <div class="tips">
      <h3>FaceDb</h3>
      <p>face 人脸数据库操作结果</p>
      <p>通过Apache Thrift Javascript client(jQuery)实现数据交互<a href="client/save.html">点击此处，预览demo</a></p>
    </div>
    <ul id="myTab" class="nav nav-tabs mt20">
      <li class="active"><a href="#client" data-toggle="tab">client调用</a></li>
      <li><a href="#Java" data-toggle="tab">Java调用</a></li>
      <li><a href="#C" data-toggle="tab">C++调用</a></li>
    </ul>
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane fade in active" id="client">
<pre>
  <code>
//引入必要的依赖文件
thrift.js、FaceDb.js、FaceDb_types.js

// 查询数据库图像数据
var transport = new Thrift.Transport("http://127.0.0.1:26432");
var protocol = new Thrift.Protocol(transport);
var client = new FaceDbClient(protocol);
$('.submit').click(function () {
  client.loadImagesMd5ByWhere(null,function(imageMd5){
    console.log(imageMd5);
  }).fail(function (jqXHR, status, error) {
    console.log(error);
  })
})
  </code>
</pre>
      </div>
      <div class="tab-pane fade" id="Java">
<pre>
  <code>
try {
  // 创建 facedb rpc client
  FaceDbThriftClient client = new FaceDbThriftClient("127.0.0.1",26431);
  // 读取图像文件为二进制字节数组
  byte[] imgData = ...
  // 调用人脸搜索方法
  FseResult[] result = client.detectAndSearchFaces(imgData, 0.5, 1, null);
  if(result.length>= 1){
    System.out.printf("result = %s\n",result[0]);
  }
} catch (ImageErrorException | NotFaceDetectedException | IOException e) {
  e.printStackTrace();
}catch (ServiceRuntimeException e) {
  e.printServiceStackTrace();
}
  </code>
</pre>
      </div>
      <div class="tab-pane fade" id="C">
<pre>
  <code>
auto client = FaceDbIfClient("127.0.0.1", 26431);
try{
  // 加载图像数据为std::string
  std::string imgData = ....
  // 调用人脸搜索方法
  auto codes = client.detectAndSearchFaces(imgData,0.5,1,nullptr);
  if(codes->size()>0){
    std::cout << (*code)[0] << std::endl; 
  } 
}
catch (net::gdface::image::ImageErrorException &e) 
{
  // 捕获服务端抛出的图像数据异常
  std::cout << e.serviceStackTraceMessage << std::endl;
}
catch (net::gdface::sdk::NotFaceDetectedException &e) 
{
  // 捕获服务端抛出的NotFaceDetectedException异常
  std::cout << e.serviceStackTraceMessage << std::endl;
}
catch (net::gdface::thrift::exception::ServiceRuntimeException &e)
{
  // 捕获服务端抛出的运行时异常(RuntimeException)
  std::cout << e.serviceStackTraceMessage << std::endl;
}
catch (std::exception& e) {
  std::cout << e.what()<< std::endl;
}
  </code>
</pre>
      </div>
    </div>
  </div>
  <script src="style/js/jquery.min.js"></script>
  <script src="style/js/bootstrap.min.js"></script>
  <script>
    if (!!window.ActiveXObject || "ActiveXObject" in window) {
      alert('请勿使用ie浏览器访问该demo，推荐使用谷歌浏览器或者360浏览器极速模式')
    }
  </script>
</body>